/*
#################################################################################
#
# Copyright (c) 2006 Michigan State University
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#################################################################################

#################################################################################
#
#	Author:
#		Nathan Collins <npcollins@gmail.com>
#
#################################################################################
*/

/* record clicks into the database via ajax */

function recordClick(rec, terms) {
	/* prepare values */
	values = "i=" + rec + "&s=" + terms

	/* send values, no div update */
	ajaxUpdateSend("url.psp?" + values)

	return true;
}

/* end */


/* focus on search box */

function focus_search() {
	document.searcher.s.focus();
}

function focus_search_adv() {
	document.creator.keywords.focus();
}

/* end */


/* validate and record history of search */

function validateMainSearch() {
	/* grab the search box */
	var searchstr = document.searcher.s.value;

	/* trim the whitespace */
	searchstr = searchstr.replace(/^\s+|\s+$/g,'');

	/* check the length */
	if (searchstr.length > 1) {
		/* record search in search history */
		addSearchHistory(searchstr);

		/* allow submit */
		return true;
	}

	/* length too short, alert user and prevent submit */
	alert( "Your search was empty or too short. Please lengthen it and try again." );
	return false;
}

/* end */


/* validate and record history of search - on results page */

function validateResultsSearch() {
	/* grab the search box */
	var searchstr = document.searcher.s.value;
	/* copy over within search if checked */
	if (document.holder.narrow.checked == true) {
		document.searcher.w.value = document.holder.hold.value;
	}

	/* trim the whitespace */
	searchstr = searchstr.replace(/^\s+|\s+$/g,'');

	/* check the length */
	if (searchstr.length > 1) {
		/* record search in search history */
		addSearchHistory(searchstr);

		/* allow submit */
		return true;
	}

	/* length too short, alert user and prevent submit */
	alert( "Your search was empty or too short. Please lengthen it and try again." );
	return false;
}

/* end */

/* return to the index page */

function home() {
	window.location = "index.psp";
}

/* end */


/* show or hide the search box on the results page */

var searchShown = 0;

function toggleSearch() {
	cbox = document.getElementById('subform1');
	sbox = document.getElementById('subform2');
	if (searchShown == 0) {
		searchShown = 1;
		cbox.innerHTML = "<span class=\"smallish details\"><a onClick=\"toggleSearch();\">Hide Search</a></span><br>";
		sbox.style.display = 'block';
		focus_search();
	}
	else {
		searchShown = 0;
		cbox.innerHTML = "<span class=\"smallish details\"><a onClick=\"toggleSearch();\">Show Search</a></span><br>";
		sbox.style.display = 'none';
	}
}

/* end */


/* get the checked value for a set of radio inputs, returns '1' is none checked */

function get_radio_value(arr) {
	max = arr.length;
	for (i = 0; i < max; i++) {
		if (arr[i].checked == true) {
			return arr[i].value;
		}
	}
	return '1';
}

/* end */

